﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.IO;

namespace GreateTool
{
    public partial class PdfRepoForm : Form
    {
        public PdfRepoForm()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            var dir = @"C:\Documents and Settings\fajian.liu\Desktop\work\2011Q3_PDFFiles";

            var files = Directory.GetFiles(dir);

            Dictionary<string, string[]> dic = new Dictionary<string, string[]>(files.Length);

            foreach (var file in files)
            {
                var arr = Path.GetFileName(file).Split('.');

                if (arr[2].Length < 6) continue;

                dic.Add(arr[3], arr);
            }

            string[] arrOut = null;

            List<string> list1 = new List<string>();
            List<string> list2 = new List<string>();
            HashSet<string> hs = new HashSet<string>(textBox1.Lines);

            foreach (var repo in textBox1.Lines)
            {
                if (!hs.Contains(repo)) continue;

                if (dic.TryGetValue(repo, out arrOut))
                {
                    var ch = arrOut[2][0];

                    var list = (ch == '6' || ch == '9') ? list1 : list2;

                    list.Add(string.Join(".", arrOut));
                }

                hs.Remove(repo);
            }

            textBox1.Lines = hs.ToArray();
            textBox2.Lines = list1.ToArray();
            textBox3.Lines = list2.ToArray();
        }

        private void button2_Click(object sender, EventArgs e)
        {
            textBox1.Clear();
            textBox2.Clear();
            textBox3.Clear();
        }

        private void button3_Click(object sender, EventArgs e)
        {
            label4.Text = string.Format("REPO {0},SHA {1},SHE {2}", textBox1.Lines.Length, textBox2.Lines.Length, textBox3.Lines.Length);
        }
    }
}
